package com.eff.android.lib.asynctask;

import android.annotation.TargetApi;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;

public class EBackgroundAsyncTask extends AsyncTask<String, String, String> {
    private static String TAG = EBackgroundAsyncTask.class.getSimpleName();
    private EIBackgroundAsyncTaskCallback mTask;

    public EBackgroundAsyncTask(EIBackgroundAsyncTaskCallback task) {
    	mTask = task;
    }

    @Override
    protected String doInBackground(String... params) {
		try {
		    mTask.processBackground();
		    this.cancel(true);
		} catch (Exception e) {
		    Log.e(TAG, "BDBackgroundTask.doInBackground - Exception", e);
		}
		return null;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public void exec() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
		    this.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "");
		} else {
		    this.execute("");
		}
    }
}
